import Vue from 'vue'
import Router from 'vue-router'
import store from '@/store/index'
import Header from '@/components/header/Header'
import Footer from '@/components/footer/Footer'
import Index from '@/page/index/Index'
import Login from '@/page/login/Index'
import Category from '@/page/category/Index'
import Mine from '@/page/mine/Index'

import Register from '@/page/register/Index'
import Findpassword from '@/page/findpassword/Index'

import Detail from '@/page/detail/Index'
import Aboutus from '@/page/aboutus/Aboutus'
import Contactus from '@/page/aboutus/Contactus'

import ClassroomList from '@/page/classroom/List'
import ClassroomDetail from '@/page/classroom/Detail'

import PromotionCompany from '@/page/promotion/promotionCompany'
import PromotionTrademark from '@/page/promotion/promotionTrademark'
import PromotionTrademarkNew from '@/page/promotion/promotionTrademarkNew'

import TrademarkList from '@/page/trademark/TrademarkList'
import TrademarkDetail from '@/page/trademark/TrademarkDetail'

import { UPDATE_TABBAR,UPDATE_USER } from "../store/mutation-types";

Vue.use(Router)

let router = new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'home',
      components: {
        default: Index,
        header: Header,
        footer: Footer
      },
    },
    {
      path: '/mine',
      name: 'mine',
      components: {
        default: Mine,
        header: Header,
        footer: Footer
      },
    },
    {
      path: '/classroom',
      name: 'classroom',
      components: {
        header: Header,
        default: ClassroomList,
        footer: Footer
      },
      meta: {
        keepAlive: true
      }
    },
    {
      path: '/classroom_detail/:id',
      name: 'classroom_detail',
      components: {
        header: Header,
        default: ClassroomDetail,
      }
    },
    {
      path: '/aboutus',
      name: 'aboutus',
      components: {
        header: Header,
        default: Aboutus,
      }
    },
    {
      path: '/contactus',
      name: 'contactus',
      components: {
        header: Header,
        default: Contactus,
      }
    },
    {
      path: '/register',
      name: 'register',
      component: Register
    },
    {
      path: '/findpassword',
      name: 'findpassword',
      component: Findpassword
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },
    {
      path: '/category',
      name: 'category',
      components: {
        default: Category,
        header: Header,
        footer: Footer
      },
      meta: {
        keepAlive: true
      }
    },
    {
      //公司注册
      path: '/detail',
      name: 'detail',
      components: {
        default: Detail,
        header: Header,
        footer: Footer
      }
    },
    {
      //公司注册推广页
      path: '/promotionCompany',
      name: 'promotionCompany',
      components: {
        default: PromotionCompany

      }
    },
    {
      //商标注册推广页
      path: '/promotionTrademark',
      name: 'promotionTrademark',
      components: {
        default: PromotionTrademark
      }
    },
    {
      //商标注册推广页NEW
      path: '/promotionTrademarkNew',
      name: 'promotionTrademarkNew',
      components: {
        header: Header,
        default: PromotionTrademarkNew
      }
    },
    {
      path: '/trademarklist',
      name: 'trademarklist',
      components: {
        header: Header,
        default: TrademarkList,
      }
    },
    {
      path: '/trademarkdetail',
      name: 'trademarkdetail',
      components: {
        header: Header,
        default: TrademarkDetail,
      },
      meta: {
        keepAlive: true
      }
    },
    {
      path: '/*',
      components: {
        default: Index,
        header: Header,
        footer: Footer
      },
    },
  ],

  scrollBehavior(to, from, savedPosition) {
    //路由跳转后在顶部
    if (savedPosition) {
      return savedPosition
    } else {
      return {x: 0, y: 0}
    }
  }
});

router.beforeEach((to, from, next) => {
  //footer中显示选中的图标
  store.commit(UPDATE_TABBAR,to.name);
  next();
});

export default router;
